home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: landen.math.uwaterloo.ca!srlalond
- From: srlalond@landen.math.uwaterloo.ca (Stephane Lalonde)
- Subject: Re: Settle a bet please
- Sender: news@undergrad.math.uwaterloo.ca (news spool owner)
- Message-ID: <Dp1JBF.1uL@undergrad.math.uwaterloo.ca>
- Date: Fri, 29 Mar 1996 17:59:39 GMT
- References: <4jfopb$o9n@news1.sympatico.ca>
- Nntp-Posting-Host: landen.math.uwaterloo.ca
- Organization: University of Waterloo
-
- Hi Gisele,
-
-
- Here is some information that will help settle the bet.
-
- 1. Strings are supported in C by a combination of language
- and library facilities
-
- 2. The language support ensure that all string constants end
- with '\0';
- i) character arrays MUST BE dimensioned 1 LARGER than
- max required.
-
- 3. '\0' is used by the string routines to locate then end of
- string, which has two draw-backs:
- i) a string cannot contain '\0'
- ii) finding the end of the string = linear search
-
- 4. Finally, all storage management of C strings is the user's
- responsibility.
-
- So, if you wan't to be able to use functions such as:
- printf("%s", Name);
- strlen(Name);
- then you must declare name to be :
- char Name[8];
-
- Hope this helps,
-
-
- Stephane
-
- In article <4jfopb$o9n@news1.sympatico.ca>, Gisele Swinson <gisele.swinson@sympatico.ca> writes:
- > In C language, how do they calculate the length of an array.
- >
- > example
- >
- > To declare a string "My Name"
- >
- > is it char name[7] = "My Name"
- > or
- > is it chat Name[8] = "My Name"
- >
- > There is a battle in my class whether to include the NULL in the
- > array size.
- >
- > I would appreciate any input you might have.
- >
- > Thanks
- >
- > Gisele
- >
-